package com.ynny.Dao.Imp;

import com.ynny.Dao.optional_coursesDao;
import com.ynny.Entity.optional_courses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public class optional_coursesDaoImp  implements optional_coursesDao{
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int addCourses(String number, String courses, BigDecimal score) {
        return 0;
    }

    @Override
    public List<optional_courses> queryAllByNumber(String number) {
        return null;
    }

    @Override
    public int addCourse(String number, String courseName, Double score) {
        String sql = "insert into optional_courses(number,courseName,score) values(?,?,?)";
        return jdbcTemplate.update(sql,number,courseName,score);
    }

    @Override
    public List<optional_coursesDao> queryCourseByNumber(String number) {
        return null;
    }


    @Override
    public optional_courses CourseByNumber(String number) {
        String sql = "select * from optional_courses where number = ?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(optional_courses.class),number);
    }

}
